package com.banmoon.algorithm.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Question589 {

    public static void main(String[] args) {

    }

    public List<Integer> preorder(Node root) {
        List<Integer> result = new ArrayList<>();
        if(root!=null){
            result.add(root.val);
            if(root.children!=null){
                for (Node child : root.children) {
                    result.addAll(preorder(child));
                }
            }
        }
        return result;
    }

}

class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};